package common.store.web.controller;

import common.store.admin.dto.Category;
import common.store.admin.service.CategoryService;
import common.store.admin.service.impl.CategoryServiceImpl;
import common.store.web.bean.Product;
import common.store.web.service.ProductService;
import common.store.web.service.impl.ProductServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/home")
public class CategoryListServlet extends HttpServlet {

    private CategoryService categoryService;


    private ProductService productService;
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        categoryService = new CategoryServiceImpl();

        List<Category> categoryList = categoryService.getCategoryList();
        productService = new ProductServiceImpl();
        List<Product> productList=productService.getHotProduct();
        //刷新列表页面的数据
        req.setAttribute("productList" , productList);
        req.setAttribute("categoryList" , categoryList);
        req.getRequestDispatcher("/index.jsp").forward(req , resp);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req , resp);
    }
}